package enduringLink.call;


public class MyQuantityHandle implements QuantityHandle{
    private volatile long totalQuantity;
    private volatile int count;

    @Override
    public void addQuantity(long quantitySum) {
        add(quantitySum);
    }

    @Override
    public void setTotalQuantity(long totalQuantity) {
//        System.out.println("setTotalQuantity = " + totalQuantity);
        this.totalQuantity = totalQuantity;
//        double avgQuantity = this.totalQuantity / 2000000;
//        RemoteHandleCenter.getResult((byte) 11, avgQuantity * 0.3);
    }

    private synchronized void add(long quantitySum){
        totalQuantity += quantitySum;
        count++;
//        System.out.println("totalQuantity = "+ totalQuantity + "  count = " + count);
    }

    public boolean isCompletion(){
        return count == 4;
    }

    public long getTotalQuantity() {
        return totalQuantity;
    }
}
